package com.zbf.timer;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author: LCG
 * @Date: 2021-11-11 00:30:09
 * @description:
 **/
public class TestTimer {

    public static Integer yyyy=0;

    public static void main(String[] args) throws ParseException {

       /* Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("=========================timer");
                yyyy=yyyy+1;
                if(yyyy==10){
                    throw new RuntimeException("抛出异常啊");
                }
            }
        },1000,1000);


        Timer timer2=new Timer();
        timer2.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("=========================timer2");
                timer2.
            }
        },1000,2000);*/

        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = simpleDateFormat.parse("2023-03-15 09:04:20");

        ThreadPoolTaskScheduler threadPoolTaskScheduler=new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setPoolSize(4);
        threadPoolTaskScheduler.initialize();
        /*threadPoolTaskScheduler.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("===============");
                if (true){
                    throw new RuntimeException("==报错测试==");
                }
            }
        },parse);*/

        for (int i=0;i<60;i++){
            String str="2023-03-15 09:10:50";
            Date parse2 = simpleDateFormat.parse(str);
            int finalI = i;
            threadPoolTaskScheduler.schedule(new Runnable() {
                @Override
                public void run() {
                    System.out.println("========"+ finalI +"=======");
                }
            },new CronTrigger("00 32 9 * * ?"));
        }



    }

}
